﻿using System;
using System.ComponentModel;

namespace HalconDotNet
{
	/// <summary>Represents an instance of a texture inspection result.</summary>
	// Token: 0x0200006E RID: 110
	public class HTextureInspectionResult : HHandle
	{
		// Token: 0x06001930 RID: 6448 RVA: 0x0000883B File Offset: 0x00006A3B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HTextureInspectionResult() : base(HHandleBase.UNDEF)
		{
		}

		// Token: 0x06001931 RID: 6449 RVA: 0x000A0290 File Offset: 0x0009E490
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HTextureInspectionResult(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06001932 RID: 6450 RVA: 0x000A029F File Offset: 0x0009E49F
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HTextureInspectionResult(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06001933 RID: 6451 RVA: 0x000A02AE File Offset: 0x0009E4AE
		private void AssertSemType()
		{
			base.AssertSemType("texture_inspection_result");
		}

		// Token: 0x06001934 RID: 6452 RVA: 0x000A02BB File Offset: 0x0009E4BB
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HTextureInspectionResult obj)
		{
			obj = new HTextureInspectionResult(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x06001935 RID: 6453 RVA: 0x000A02D4 File Offset: 0x0009E4D4
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HTextureInspectionResult[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HTextureInspectionResult[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HTextureInspectionResult(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Inspection of the texture within an image.
		///   Modified instance represents: Handle of the inspection results.
		/// </summary>
		/// <param name="image">Image of the texture to be inspected.</param>
		/// <param name="noveltyRegion">Novelty regions.</param>
		/// <param name="textureInspectionModel">Handle of the texture inspection model.</param>
		// Token: 0x06001936 RID: 6454 RVA: 0x000A0344 File Offset: 0x0009E544
		public HTextureInspectionResult(HImage image, out HRegion noveltyRegion, HTextureInspectionModel textureInspectionModel)
		{
			IntPtr proc = HalconAPI.PreCall(2044);
			HalconAPI.Store(proc, 1, image);
			HalconAPI.Store(proc, 0, textureInspectionModel);
			HalconAPI.InitOCT(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			num = HRegion.LoadNew(proc, 1, num, out noveltyRegion);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(image);
			GC.KeepAlive(textureInspectionModel);
		}

		/// <summary>Add training images to the texture inspection model.</summary>
		/// <param name="image">Image of flawless texture.</param>
		/// <param name="textureInspectionModel">Handle of the texture inspection model.</param>
		/// <returns>Indices of the images that have been added to the texture inspection model.</returns>
		// Token: 0x06001937 RID: 6455 RVA: 0x000A03B8 File Offset: 0x0009E5B8
		public static HTuple AddTextureInspectionModelImage(HImage image, HTextureInspectionModel textureInspectionModel)
		{
			IntPtr proc = HalconAPI.PreCall(2043);
			HalconAPI.Store(proc, 1, image);
			HalconAPI.Store(proc, 0, textureInspectionModel);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, HTupleType.INTEGER, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(image);
			GC.KeepAlive(textureInspectionModel);
			return result;
		}

		/// <summary>
		///   Inspection of the texture within an image.
		///   Modified instance represents: Handle of the inspection results.
		/// </summary>
		/// <param name="image">Image of the texture to be inspected.</param>
		/// <param name="textureInspectionModel">Handle of the texture inspection model.</param>
		/// <returns>Novelty regions.</returns>
		// Token: 0x06001938 RID: 6456 RVA: 0x000A0410 File Offset: 0x0009E610
		public HRegion ApplyTextureInspectionModel(HImage image, HTextureInspectionModel textureInspectionModel)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(2044);
			HalconAPI.Store(proc, 1, image);
			HalconAPI.Store(proc, 0, textureInspectionModel);
			HalconAPI.InitOCT(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HRegion result;
			num = HRegion.LoadNew(proc, 1, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(image);
			GC.KeepAlive(textureInspectionModel);
			return result;
		}

		/// <summary>Clear a texture inspection result handle and free the allocated memory. </summary>
		/// <param name="textureInspectionResultID">Handle of the texture inspection results.</param>
		// Token: 0x06001939 RID: 6457 RVA: 0x000A0484 File Offset: 0x0009E684
		public static void ClearTextureInspectionResult(HTextureInspectionResult[] textureInspectionResultID)
		{
			HTuple htuple = HHandleBase.ConcatArray(textureInspectionResultID);
			IntPtr proc = HalconAPI.PreCall(2048);
			HalconAPI.Store(proc, 0, htuple);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(htuple);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(textureInspectionResultID);
		}

		/// <summary>
		///   Clear a texture inspection result handle and free the allocated memory. 
		///   Instance represents: Handle of the texture inspection results.
		/// </summary>
		// Token: 0x0600193A RID: 6458 RVA: 0x000A04C8 File Offset: 0x0009E6C8
		public void ClearTextureInspectionResult()
		{
			IntPtr proc = HalconAPI.PreCall(2048);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>Get the training images contained in a texture inspection model.</summary>
		/// <param name="textureInspectionModel">Handle of the texture inspection model.</param>
		/// <returns>Training images contained in the texture inspection model.</returns>
		// Token: 0x0600193B RID: 6459 RVA: 0x000A04FC File Offset: 0x0009E6FC
		public static HImage GetTextureInspectionModelImage(HTextureInspectionModel textureInspectionModel)
		{
			IntPtr proc = HalconAPI.PreCall(2075);
			HalconAPI.Store(proc, 0, textureInspectionModel);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			HImage result;
			num = HImage.LoadNew(proc, 1, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(textureInspectionModel);
			return result;
		}

		/// <summary>
		///   Query iconic results of a texture inspection.
		///   Instance represents: Handle of the texture inspection result.
		/// </summary>
		/// <param name="resultName">Name of the iconic object to be returned. Default: "novelty_region"</param>
		/// <returns>Returned iconic object.</returns>
		// Token: 0x0600193C RID: 6460 RVA: 0x000A0544 File Offset: 0x0009E744
		public HObject GetTextureInspectionResultObject(HTuple resultName)
		{
			IntPtr proc = HalconAPI.PreCall(2077);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, resultName);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(resultName);
			HObject result;
			num = HObject.LoadNew(proc, 1, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Query iconic results of a texture inspection.
		///   Instance represents: Handle of the texture inspection result.
		/// </summary>
		/// <param name="resultName">Name of the iconic object to be returned. Default: "novelty_region"</param>
		/// <returns>Returned iconic object.</returns>
		// Token: 0x0600193D RID: 6461 RVA: 0x000A059C File Offset: 0x0009E79C
		public HObject GetTextureInspectionResultObject(string resultName)
		{
			IntPtr proc = HalconAPI.PreCall(2077);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, resultName);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			HObject result;
			num = HObject.LoadNew(proc, 1, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>Train a texture inspection model.</summary>
		/// <param name="textureInspectionModel">Handle of the texture inspection model.</param>
		// Token: 0x0600193E RID: 6462 RVA: 0x000A05EC File Offset: 0x0009E7EC
		public static void TrainTextureInspectionModel(HTextureInspectionModel textureInspectionModel)
		{
			IntPtr proc = HalconAPI.PreCall(2099);
			HalconAPI.Store(proc, 0, textureInspectionModel);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(textureInspectionModel);
		}
	}
}
